import { UserService } from '../../services'
import { USERNAME_TEST, PASSWORD_TEST } from '../../constance/Reg'
import localCache from '../../utils/localCache'
export default {
  data() {
    return {
      username: '米超强',
      password: 'mima123456',
      usernamePattern: USERNAME_TEST,
      passwordPattern: PASSWORD_TEST
    }
  },
  methods: {
    async onSubmit(values) {
      const res = await UserService.login(values)
      if (res.data.status === 200 && res.data.msg === '登录成功') {
        localCache.setLocalCache('miBlogToken', res.data.token)
        this.$store.commit('isLogin')
        this.$router.push('/')
        this.$notify({ type: 'success', message: res.data.msg })
      } else {
        this.$notify({ type: 'danger', message: res.data.msg })
      }
    },
    onClickLeft() {
      this.$router.push('/')
    },
    goRegistry() {
      this.$router.push('/registry')
    }
  }
}
